using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

using BadException;
using BadUtil;
using BadWeb;

namespace FlickrClient
{
	public static class Session
	{
		public static void GetToken()
		{
			byte[] secretbytes = Encoding.UTF8.GetBytes(Api.API_SECRET);
			byte[] keybytes = Encoding.UTF8.GetBytes("api_key"+Api.API_KEY);
			byte[] frobbytes = Encoding.UTF8.GetBytes("frob");
			byte[] permsbytes = Encoding.UTF8.GetBytes("permswrite");

			byte[] allbytes = new byte[secretbytes.Length + keybytes.Length + frobbytes.Length + permsbytes.Length];
			//byte[] allbytes = new byte[secretbytes.Length + keybytes.Length + permsbytes.Length];

            Array.Copy(secretbytes, allbytes, secretbytes.Length);
			Array.Copy(keybytes, 0, allbytes, secretbytes.Length, keybytes.Length);
			Array.Copy(frobbytes, 0, allbytes, (int)(secretbytes.Length + keybytes.Length), frobbytes.Length);
			Array.Copy(permsbytes, 0, allbytes, (int)(secretbytes.Length + keybytes.Length + frobbytes.Length), permsbytes.Length);
			//Array.Copy(permsbytes, 0, allbytes, (int)(secretbytes.Length + keybytes.Length), permsbytes.Length);

			byte[] hash = MD5.Create().ComputeHash(allbytes);
			string hexstring = HexString.FromBytes(hash);

			object[] stringparams = new object[4];
			stringparams[0] = Api.API_KEY;
			stringparams[1] = "write";
			stringparams[2] = "";
			stringparams[3] = hexstring;

			string url = string.Format(UrlConstants.LOGIN, stringparams);

			string response = Get.DoGet(url, HttpConstants.X_WWW_URLENCODED);


		}
	}
}
